package com.fengxu.nio;

import java.nio.IntBuffer;

public class BasicBuffer {

    public static void main(String[] args) {

        // 创建一个Buffer,大小为5，可存放5个int
        IntBuffer intBuffer = IntBuffer.allocate(5);

        // 赋值
        for (int i = 0; i < intBuffer.capacity(); i++){
            intBuffer.put(i * 2);
        }

        // 读写切换,切换到读模式（实质上是反转索引）
        intBuffer.flip();

        // 读取数据
        while (intBuffer.hasRemaining()){
            System.out.println(intBuffer.get());
        }
    }
}
